var mysql = require('mysql')
const db_config = {
    host:'localhost',
    database:"test",
    user:'root',
    password:"root"
}
var connection
function init(){
    connection = mysql.createConnection(db_config)
    connection.connect()
}
function getQuery(sqlQuery) {
    return new Promise((resolve, reject) => {
      connection.query(sqlQuery, function(err, result) {
        if(err) reject(`SQL Error: ${err}`)
        resolve(result)
      })    
    })
}
async function getData(sqlQuery) {
    init()
    let sqlStr = await getQuery(sqlQuery)
    end()
    return sqlStr
}
function end(){
    connection.end()
}
// connection.connect()
module.exports = {
    getData,
}
